package stalker.user;

import message.Message;
import message.controller.MessageController;
import message.visitor.singleton.UserManagerVisitor;
import stalker.Stalker;

/**
 * Manages creation of rooms
 */

public class UserManager extends Stalker {
  
  private final MessageController<Void> user_controller_;
  
  private void checkRep() {
    assert (user_controller_ != null) :
      "UserManager: fields must not be null";
    assert (Stalker.getStalker(this.getID()) == this) :
      "UserManager: Inconsistent data";
  }
  
  /**
   * Creates a new user manager
   * 
   * @requires name is not null, name is unique
   * @param name Name of this room.
   */
  
  public UserManager() {
    super("User Manager");
    user_controller_ = new MessageController<Void>(new UserManagerVisitor());
    new Thread(user_controller_).start();
    checkRep();
  }
  
  /**
   * Accepts a request
   * @requires request not null
   * @param request A request made to the room
   */
  @Override
  public void acceptMessage(Message message) {
    assert message != null;
    user_controller_.enqueueMessage(message);
  }
}
